import Bot_client from "../bot/amesu";
import { Bot_msg } from "../bot/bot_msg";
export enum Emitter_bot {
    login_start,
    /**
     * 机器人登陆成功
     */
    login_succress,
    login_error,
    /**
     * 用户输入文字
     */
    user_input,
    /**
     * 服务器断开连接
     */
    server_off,
    /**
     * 服务器连接成功
     */
    server_online
}
export enum mathType {
    /**
     * 匹配指令开头
     */
    math_start,
    /**
     * 匹配全部指令
     */
    math_all,
}
let mathMap: Map<string, { mathType: mathType, mathStr: string, action: any, self: any, isHideMath: boolean }> = new Map();
export let mathList:{ mathType: mathType, mathStr: string, action: any, self: any, isHideMath: boolean }[] = [];
export class packge {
    constructor() {
        // 注册指令监听
        this.init();
    }
    init() {

    }
     /**
     * 将字符串转为 数字 + 文字
     * 例:11哈哈 -> [11,"哈哈"]
     * @param str 
     * @returns 
     */
    cover_NumStr(str) {
        let matches = str.match(/(\d+)([\s\S]+)/);
        if (matches) {
            let number = Number(matches[1]); // 提取数字部分
            let content = matches[2]; // 提取第一组数字之后的所有内容
            return [number, content];
        } else {
            return [0, str]; // 如果没有找到数字，则返回0和原始字符串内容
        }
    }
    help(dir: string, msg: Bot_msg) {
        const obj = {
            template: '',
            tolocation: msg.getFormId(),
            data: {}
        }
        const module = require(`../../template/Help/${dir}`);
        module.default(obj);
    }
    /**
* 字符串过滤数字无关的值
* @param str 
* @returns 
*/
    getNumber(str: string) {
        if (!str) {
            return 0
        }
        while (str.includes('万亿')) {
            str = str.replace('万亿', '000000000000')
        }
        while (str.includes('千亿')) {
            str = str.replace('千亿', '00000000000')
        }
        while (str.includes('百亿')) {
            str = str.replace('百亿', '0000000000')
        }
        while (str.includes('十亿')) {
            str = str.replace('十亿', '000000000')
        }
        while (str.includes('亿')) {
            str = str.replace('亿', '00000000')
        }

        while (str.includes('千万')) {
            str = str.replace('千万', '0000000')
        }
        while (str.includes('百万')) {
            str = str.replace('百万', '000000')
        }
        while (str.includes('十万')) {
            str = str.replace('十万', '00000')
        }
        while (str.includes('万')) {
            str = str.replace('万', '0000')
        }
        let numStr = str.replace(/[^0-9]/ig, "");

        return Number(numStr);
    }
    /**
     * 获取到指令中的数字
     * 用例:指令+数字
     * @param msg 
     * @param filter 
     * @returns 
     */
    getCommonNum(msg: Bot_msg, filter: string) {
        let arry = msg.getContent().split(filter);
        let idx: any = arry[1];
        idx = this.getNumber(idx);
        return idx;
    }
    random(min: number, max: number) {
        return Math.floor(Math.random() * (max - min + 1)) + min
    }
    /**
     * 注册
     * 删除
     * 监听一次
     * @param key 
     * @param call 
     */
    register_botLiset(key: Emitter_bot, call: Function) {
        Bot_client.on(key, call);
    }
    /**
     * class
     * mathType
     * mathStr
     */
    addMath(mathType: mathType, mathStr: string, call: any, self, isHideMath = true) {
        mathStr = mathStr.toUpperCase()
        mathMap.set(mathStr, {
            mathType: mathType,
            action: call,
            isHideMath: isHideMath,
            mathStr: mathStr,
            self: self
        })
        mathList = [...this.get_mathMap().values()].sort((a, b) => b.mathStr.length - a.mathStr.length);
    }
    get_mathMap() {
        return mathMap;
    }
    get_mathList(){
        return mathList;
    }
    lisent(msg) {

    }
}